package org.dromara.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.XfNews;
import org.dromara.system.domain.XfRatingDimension;
import org.dromara.system.domain.XfReviewRating;
import org.dromara.system.domain.query.XfReviewRatingQuery;
import org.dromara.system.domain.vo.XfNewsVo;
import org.dromara.system.domain.vo.XfReviewRatingVo;
import org.dromara.system.mapper.XfReviewRatingMapper;
import org.dromara.system.service.IXfReviewRatingService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class XfReviewRatingServiceImpl extends ServiceImpl<XfReviewRatingMapper, XfReviewRating> implements IXfReviewRatingService {

    @Override
    public TableDataInfo<XfReviewRatingVo> selectPageXfReviewRatingList(XfReviewRatingQuery query) {
        Page<XfReviewRating> page = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<XfReviewRating> wrapper = Wrappers.lambdaQuery();

        // 根据新闻ID查询
        wrapper.eq(query.getReviewId() != null, XfReviewRating::getReviewId, query.getReviewId());


        Page<XfReviewRatingVo> result = baseMapper.selectPageXfReviewRatingList(page, wrapper);
        return TableDataInfo.build(result);
    }

    @Override
    public List<XfReviewRatingVo> selectXfReviewRatingList(XfReviewRatingQuery query) {
        return baseMapper.queryListByReviewId(query);
        // queryList()
    }

    @Override
    public XfReviewRatingVo selectXfReviewRatingById(Long id) {
        return baseMapper.selectVoById(id);
    }

    @Override
    public boolean insertXfReviewRating(XfReviewRating reviewRating) {
        return this.save(reviewRating);
    }

    @Override
    public boolean updateXfReviewRating(XfReviewRating reviewRating) {
        return this.updateById(reviewRating);
    }

    @Override
    public int deleteXfReviewRatingById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int deleteXfReviewRatingByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(List.of(ids));
    }
}
